function error_value = processing_error_1d(left, right, N, basis_type, N_gauss_int1d, function_u, U, error_type)

[node, elem] = processing_node_elem_bdary_1d(left, right, N, basis_type, "Dirichlet");
dN = reference_basis_function_1d(basis_type);

switch error_type
    case "Max"
        error_value = max(abs(function_u(node) - U(node)));

    case "Linf"
        sum_n = zeros(1,size(elem,1));
        for n = 1:size(elem,1)
            E = node(elem(n,:));
            a = E(1);
            b = E(2);
            psi = function_transform_1d(-1, 1, dN, a, b);
            sum_u = @(x) 0;
            for k = 1:size(elem,2)
                i = elem(n,k);
                sum_u = @(x) sum_u(x) + U(i).*psi{k}(x);
            end
            diff_func = @(x) abs(function_u(x) - sum_u(x));
            gausspoints = gauss_points_weights_1d(9);
            sorted_points = sort([gausspoints(1), gausspoints(2:5), -gausspoints(2:5)], "ascend");
            local_points = function_transform_1d(-1, 1, sorted_points, a, b);
            sum_n(1,n) = max(diff_func(local_points));
        end
        error_value = max(sum_n);

    case "L2"
        sum_n = 0;
        for n = 1:size(elem,1)
            E = node(elem(n,:));
            a = E(1);
            b = E(2);
            psi = function_transform_1d(-1, 1, dN, a, b);
            sum_u = @(x) 0;
            for k = 1:size(elem,2)
                i = elem(n,k);
                sum_u = @(x) sum_u(x) + U(i).*psi{k}(x);
            end
            int_func = @(x) (function_u(x) - sum_u(x)).^2;
            sum_n = sum_n + gauss_int1d(int_func, a, b, N_gauss_int1d);
        end
        error_value = sqrt(sum_n);

    case "H1"
        sum_n = 0;
        for n = 1:size(elem,1)
            E = node(elem(n,:));
            a = E(1);
            b = E(2);
            psi = function_transform_1d(-1, 1, dN, a, b);
            psi = function_symbolic_computing_1d(psi, "dx");
            sum_u = @(x) 0;
            for k = 1:size(elem,2)
                i = elem(n,k);
                sum_u = @(x) sum_u(x) + U(i).*psi{k}(x);
            end
            int_func = @(x) (function_u(x) - sum_u(x)).^2;
            sum_n = sum_n + gauss_int1d(int_func, a, b, N_gauss_int1d);
        end
        error_value = sqrt(sum_n);

    otherwise
        error('Invalid error type.')
end

end